﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;

using eSYSU.DAL;
using eSYSU.Model;
using eSYSU.IBusiness;


namespace eSYSU.Business
{
    /// <summary>
    ///CollegeService 的摘要说明
    /// </summary>
    public class CollegeService
    {
        public CollegeService()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }


        /// <summary>
        /// 插入一条学院记录
        /// </summary>
        /// <param name="college">学院模型对象</param>
        public static void CollegeInsert(College college)
        {
            IDictionary<string, object> parmsDic = new Dictionary<string, object>();
            parmsDic.Add("@CName", college.name);
            parmsDic.Add("@CBrief", college.brief);
            parmsDic.Add("@CLogo", college.logo);
            parmsDic.Add("@COrder", college.order);

            SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_College_Insert", parmsDic);
        }


        /// <summary>
        /// 获取指定学院的记录（ID为零则获取全部学院记录）
        /// </summary>
        /// <param name="iCollegeID">学院编号（ID为零则获取全部学院记录）</param>
        /// <returns>DataTable对象</returns>
        public static DataTable GetColleges(int iCollegeID)
        {
            if (iCollegeID > -1)
            {
                IDictionary<string, object> parmsDic = new Dictionary<string, object>();
                parmsDic.Add("@_id", iCollegeID);

                return SqlHelper.GetDataTable(SqlHelper.ConnString, CommandType.StoredProcedure, "proc_College_Get", parmsDic);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 创建学院Logo的缩略图
        /// </summary>
        /// <param name="sOriginalLogoPath">用于生成缩略图的Logo源图地址</param>
        /// <param name="sDestinationLogoPaths">缩略图生成路径（包含扩展名）的字符串数组</param>
        /// <param name="iSize">缩略图的尺寸（与路径数组长度要一致）</param>
        /// <returns>生成结果</returns>
        public static bool CreateLogoThumbnail(string sOriginalLogoPath, string[] sDestinationLogoPaths, int[,] iSize)
        {
            try
            {
                for (int i = 0; i < sDestinationLogoPaths.Length; i++)
                {
                    eSYSU.Common.ImageHelper.CreateThumbnail(sOriginalLogoPath, sDestinationLogoPaths[i], iSize[i, 0], iSize[i, 1]);
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}